package com.erp.servlet;

import com.erp.bean.Order;
import com.erp.bean.OrderState;
import com.erp.service.OrderService;
import com.erp.service.OrderStateService;
import com.erp.service.impl.OrderServiceImpl;
import com.erp.service.impl.OrderStateServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author mtf
 * 更改订单退换货的状态
 */
@WebServlet("/evaluateeditstate.action")
public class EvaluateEditStateServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建订单业务逻辑对象
        OrderService orderService = new OrderServiceImpl();
        //接收信息
        String oid = req.getParameter("oid");

        //通过订单编号找到订单对象
        Order order = orderService.findById(oid);

            System.out.println(2);
            //将订单状态设置为退换货待审批
            order.setSid(4);
            //外键
            System.out.println(order);
            //调用修改的方法
            boolean flag = orderService.update(order);
            System.out.println(flag);
        try {
            //给个反应时间
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //重定向到退换货列表控制器
            resp.sendRedirect("orderbarter.action");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
